package com.intelligent.system.common.exception;

import com.intelligent.system.common.response.ResponseCode;
import com.intelligent.system.common.response.ResultDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(CustomException.class)
    public ResultDO<Void> handleCustomException(CustomException e) {
        log.error("业务异常: {}", e.getMessage(), e);
        return ResultDO.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResultDO<Void> handleException(Exception e) {
        log.error("系统异常: {}", e.getMessage(), e);
        return ResultDO.error(ResponseCode.INTERNAL_SERVER_ERROR.getCode(), 
            ResponseCode.INTERNAL_SERVER_ERROR.getMessage());
    }
}